
/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：                                                    
*│　作    者：gaotang                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-01-04 10:01:02                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： BestTrader.Cms.Services                                  
*│　类    名： CacheService                                    
*└──────────────────────────────────────────────────────────────┘
*/
using AutoMapper;
using BestTrader.Cms.Core;
using BestTrader.Cms.Core.Helper;
using BestTrader.Cms.IRepository;
using BestTrader.Cms.IServices;
using BestTrader.Cms.RmmfSoftServices;
using BestTrader.Cms.RmmfSoftServices.Models;
using BestTrader.Cms.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BestTrader.Cms.Services
{
    public class CacheService : ICacheService
    {
        private readonly ISysItemsDetailService _itemService;
        private readonly RmmfSoftAccountService _rmmfService;
        private readonly IManagerRepository _managerRepository;
        private readonly IMapper _mapper;

        public CacheService(ISysItemsDetailService itemService, IManagerRepository managerRepository, IMapper mapper, RmmfSoftAccountService rmmfService)
        {
            this._itemService = itemService;
            this._rmmfService = rmmfService;
            this._mapper = mapper;
            this._managerRepository = managerRepository;
        }

        ///// <summary>
        ///// 获取所有的代理用户
        ///// </summary>
        ///// <returns></returns>
        //public List<ItemsDetailModel> GetCacheAgentManagers()
        //{
        //    var users = CacheHelper.Get<List<ItemsDetailModel>>(Constants.CACHE_AGENT_MANAGER);
        //    if (users == null || !users.Any())
        //    {
        //        var managers = _managerRepository.GetCacheAllAgentManager();
        //        users = _mapper.Map<List<ItemsDetailModel>>(managers);
        //        CacheHelper.Set(Constants.CACHE_AGENT_MANAGER, users);
        //    }
        //    return users;
        //}

        /// <summary>
        /// 获取所有的货币类型
        /// </summary>
        /// <returns></returns>
        public List<ItemsDetailModel> GetCacheCurrencyTypes()
        {
            var currencies = CacheHelper.Get<List<ItemsDetailModel>>(Constants.CACHE_CURRENCY_TYPE);
            if (currencies == null || !currencies.Any())
            {
                currencies = _itemService.GetItems("CurrencyType");
                CacheHelper.Set(Constants.CACHE_CURRENCY_TYPE, currencies);
            }
            return currencies;
        }

        /// <summary>
        /// 获取所有的交易代码
        /// </summary>
        public List<ItemsDetailModel> GetCacheProjectTypes()
        {
            var projects = CacheHelper.Get<List<ItemsDetailModel>>(Constants.CACHE_PROEJCT_TYPE);
            if (projects == null || !projects.Any())
            {
                projects = _itemService.GetItems("ProjectType");
                CacheHelper.Set(Constants.CACHE_PROEJCT_TYPE, projects);
            }
            return projects;
        }

        public List<FirmStructureModel> GetRmmfDepts()
        {
            var depts = CacheHelper.Get<List<FirmStructureModel>>(Constants.CACHE_RMMSOFT_DEPTS);
            if (depts == null || !depts.Any())
            {
                depts = _rmmfService.GetFirmStructure();
                CacheHelper.Set(Constants.CACHE_RMMSOFT_DEPTS, depts);
            }

            return depts;
        }

        public List<UserRoleOutput> GetRmmfRoles()
        {
            var roles = CacheHelper.Get<List<UserRoleOutput>>(Constants.CACHE_RMMSOFT_ROLES);
            if (roles == null || !roles.Any())
            {
                roles = _rmmfService.GetAllUserRoles();
                CacheHelper.Set(Constants.CACHE_RMMSOFT_ROLES, roles);
            }

            return roles;
        }

    }
}